<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>控制台-产品管理-浙江星全汽车服务有限公司</title>
		<meta name="keywords" content="控制台" />
		<meta name="description" content="控制台" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />

		<!-- basic styles -->

		<link href="/public/static/admin/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="/public/static/admin/css/font-awesome.min.css" />

		<!--[if IE 7]>
		  <link rel="stylesheet" href="/public/static/admin/css/font-awesome-ie7.min.css" />
		<![endif]-->

		<!-- page specific plugin styles -->

		<link rel="stylesheet" href="/public/static/admin/css/ace.min.css" />
		<link rel="stylesheet" href="/public/static/admin/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="/public/static/admin/css/ace-skins.min.css" />

		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="/public/static/admin/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->

		<script src="/public/static/admin/js/ace-extra.min.js"></script>

		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

		<!--[if lt IE 9]>
		<script src="/public/static/admin/js/html5shiv.js"></script>
		<script src="/public/static/admin/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>
		<div class="navbar navbar-default" id="navbar">
			<script type="text/javascript">
				try{ace.settings.check('navbar' , 'fixed')}catch(e){}
			</script>

			<div class="navbar-container" id="navbar-container">
				<div class="navbar-header pull-left">
					<a href="#" class="navbar-brand">
						<small>
							控制台-浙江星全汽车服务有限公司
						</small>
					</a><!-- /.brand -->

				</div><!-- /.navbar-header -->
				<div class="navbar-header pull-right">
					<button type="button" id="logOut" class="btn btn-sm btn-danger" data-toggle="button" style="margin-top:5px;">退出</button>
				</div>
			</div><!-- /.container -->
		</div>

		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				<div class="sidebar" id="sidebar">
					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'fixed')}catch(e){}
					</script>

					<ul class="nav nav-list">
						<li>
							<a href="/admin/index/brand">
								<i class="icon-list-alt"></i>
								<span class="menu-text"> 品牌管理 </span>
							</a>
						</li>

						<li class="active">
							<a href="/admin/index/product">
								<i class="icon-list"></i>
								<span class="menu-text"> 产品管理 </span>
							</a>
						</li>
						<li>
							<a href="/admin/index/intention">
								<i class="icon-edit"></i>
								<span class="menu-text"> 购车意向 </span>
							</a>
						</li>
					</ul><!-- /.nav-list -->

					<div class="sidebar-collapse" id="sidebar-collapse">
						<i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
					</div>

					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'collapsed')}catch(e){}
					</script>
				</div>

				<div class="main-content">
					<div class="page-content">
						<div class="page-header">
							<h1>
								产品管理
							</h1>
						</div>
						<div class="pull-left">
							<label>品牌选择</label>
							 <form id="serachForm" enctype="multipart/form-data" method="get" action="/admin/index/product">
							<select name="serachBrandSelect" >
								<option value="-1">请选择品牌</option>
								<?php 
								if (is_array($brandList) && count($brandList) > 0) {
									foreach ($brandList as $value) {
										if ($value['id'] == $brandSerach) {
											echo "<option value='".$value['id']."' selected>".$value['name']."</option>";
										} else {
											echo "<option value='".$value['id']."'>".$value['name']."</option>";
										}
									}
								}

								?>
							</select>

							<button id="search" class="btn-sm btn-primary">搜索</button>
							</form>
						</div>
						<div class="navbar pull-right">
							<button id="addProduct" class="btn btn-info">产品添加</button>
						</div>
						
						<div class="row">
							<div class="col-xs-12">
								<div class="table-responsive">
									<table id="sample-table-2" class="table table-striped table-bordered table-hover">
										<thead>
											<tr>
												<th>车型名称</th>
												<th>车型简介</th>
												<th>星全价</th>
												<th>添加时间</th>
												<th>修改时间</th>
												<th>操作</th>
											</tr>
										</thead>

										<tbody>
											<?php
												if ($list != null && isset($list['list']) && $list['list'] != null && is_array($list['list']) && count($list['list']) > 0) {
													foreach ($list['list'] as $value) {
														echo "<tr>";
														echo "<td>".$value['name']."</td>";
														echo "<td>".$value['abstract']."</td>";
														echo "<td>".$value['star_price']."</td>";
														echo "<td>".$value['add_time']."</td>";
														echo "<td>".$value['update_time']."</td>";
														echo "<td>";

														echo '<div class="action-buttons">';
														echo '<a class="green" onclick="editProduct('.$value["id"].')"><i class="icon-pencil bigger-130"></i></a>';
														echo "&nbsp;";
														echo '<a class="red" onclick="delProduct('.$value["id"].')"><i class="icon-trash bigger-130"></i></a>';
														echo "</div>";
														echo "</td>";
														echo "</tr>";
													}
												}

											?>	
										</tbody>
									</table>
								</div>
							</div>
						</div>

						<div class="row">
							<div class="col-sm-6">
								<div class="dataTables_info" id="sample-table-2_info">Showing<?php echo $list['pageStart']." to ". $list['pageEnd'] ." of ". $list["count"]; ?> entries</div>
							</div>
							<div class="col-sm-6">
								<div class="dataTables_paginate paging_bootstrap">
									<ul class="pagination">
										<li <?php if($list['firstPage'] == $list['thisPage']) {
												echo 'class="prev disabled"';
											} ?>>
											<a href="/admin/index/product?page=1" data-page="<?php echo $list['firstPage']?>"><i class="icon-double-angle-left"></i></a>
										</li>
										<?php 
											if (isset($list['pageList']) && is_array($list['pageList']) && count($list['pageList']) > 0) {

												
												foreach ($list['pageList'] as $pageList) {
													if ($pageList > 0 ) {
														if ($pageList == $list['getPage']) {
														echo "<li class=\"active\"><a href=\"/admin/index/product?page=".$pageList."&serachBrandSelect=".$brandSerach."\" data-page='".$pageList."'>".$pageList."</a>";
														} else {
															echo "<li><a href=\"/admin/index/product?page=".$pageList."&serachBrandSelect=".$brandSerach."\" data-page='".$pageList."'>".$pageList."</a>";
														}
													}
												}
											}

										?>
										
										<li <?php if($list['lastPage'] == $list['thisPage']) {
												echo 'class="prev disabled"';
											} ?>>
											<a href="<?php echo '/admin/index/product?page='.$list['lastPage'] ?>" data-page="<?php echo $list['lastPage']?>"><i class="icon-double-angle-right"></i></a>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</div><!-- /.page-content -->
				</div><!-- /.main-content -->
			</div><!-- /.main-container-inner -->

		</div><!-- /.main-container -->

		<div class="bootbox modal fade in" id="addProductInfo" tabindex="-1" role="dialog" aria-hidden="false" style="display:none;height:100%;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">  
			      		<button type="button" class="bootbox-close-button close closeAddProductInfo" style="margin-top: -10px;">×</button>
						<div class="bootbox-body">
			      			<h4 class="modal-title">添加产品</h4>  
			    		</div> 
			    	</div>
			    	<form id="productForm" enctype="multipart/form-data">
						<div class="modal-body">
							<div class="form-group">
								<label class="col-sm-4 control-label"> 选择品牌 *</label>
								<div class="col-sm-8">
									<select name="productBrandSelect" >
										<option value="-1">请选择品牌</option>
										<?php 
										if (is_array($brandList) && count($brandList) > 0) {
											foreach ($brandList as $value) {
												echo "<option value='".$value['id']."'>".$value['name']."</option>";
											}
										}
										?>
									</select>
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型名称 *</label>
								<div class="col-sm-8">
									<input type="text" id="name" placeholder="车型名称" class="col-xs-12 col-sm-12">
								</div>
							</div>
							<br/>
							<div class="form-group" style="padding-bottom: 10px;">
								<label class="col-sm-4 control-label"> 车型简介 *</label>
								<div class="col-sm-8">
									<textarea  type="text" id="abstract" placeholder="车型简介" class="col-xs-12 col-sm-12"></textarea>
								</div>
							</div>
							<br/>
							<div class="form-group" style="padding-top: 10px;">
								<label class="col-sm-4 control-label">
									推荐热门 *
								</label>
								<div class="col-sm-8">
									<input type="checkbox" checked="" value="Yes" offval="No" id="isHot" name="isHot" role="checkbox" class="editable ace ace-switch ace-switch-5">
									<span class="lbl"></span>
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 星全价 *</label>
								<div class="col-sm-8">
									<input type="text" id="starPrice" placeholder="星全价" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 指导价 *</label>
								<div class="col-sm-8">
									<input type="text" id="guidancePrice" placeholder="指导价" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 优惠金额 *</label>
								<div class="col-sm-8">
									<input type="text" id="discount" placeholder="优惠金额" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 落地参考价 *</label>
								<div class="col-sm-8">
									<input type="text" id="actualPrice" placeholder="落地参考价" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车辆图片 *</label>
								<div class="col-sm-8">
									<input type="file" id="img" name="img" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点大图 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic1" name="pic1" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点小图1 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic2" name="pic2" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点小图2 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic3" name="pic3" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点小图3 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic4" name="pic4" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型参数 *</label>
								<div class="col-sm-8">
									<input type="file" id="excel1" name="excel1" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型参数配置 *</label>
								<div class="col-sm-8">
									<input type="file" id="excel2" name="excel2" value="">
								</div>
							</div>
						</div>
					</form>
					<div class="modal-footer">
						<button id="addProductInfoButton" type="button" class="btn btn-sm btn-success">
							<i class="icon-ok"></i>保存
						</button>
						<button data-bb-handler="button" type="button" class="btn btn-sm closeAddProductInfo">取消
						</button>
					</div>
				</div>
			</div>
		</div>

		<div class="bootbox modal fade in" id="editProductInfo" tabindex="-1" role="dialog" aria-hidden="false" style="display:none;height:100%;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">  
			      		<button type="button" class="bootbox-close-button close closeEditProductInfo" style="margin-top: -10px;">×</button>
						<div class="bootbox-body">
			      			<h4 class="modal-title">编辑产品</h4>  
			    		</div> 
			    	</div>
			    	<form id="editProductForm" enctype="multipart/form-data">
						<div class="modal-body">
							<div class="form-group">
								<input type="hidden" id="productId">
								<label class="col-sm-4 control-label"> 选择品牌 *</label>
								<div class="col-sm-8">
									<select name="productBrandSelect" >
										<option value="-1">请选择品牌</option>
									</select>
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型名称 *</label>
								<div class="col-sm-8">
									<input type="text" id="name" placeholder="车型名称" class="col-xs-12 col-sm-12">
								</div>
							</div>
							<br/>
							<div class="form-group" style="padding-bottom: 10px;">
								<label class="col-sm-4 control-label"> 车型简介 *</label>
								<div class="col-sm-8">
									<textarea type="text" id="abstract" placeholder="车型简介" class="col-xs-12 col-sm-12"></textarea>
								</div>
							</div>
							<br/>
							<div class="form-group" style="padding-top: 10px;">
								<label class="col-sm-4 control-label">
									推荐热门 *
								</label>
								<div class="col-sm-8 isHotCheckbox">
									<input type="checkbox" value="Yes" offval="No" id="isHot" name="isHot" role="checkbox" class="editable ace ace-switch ace-switch-5">
									<span class="lbl"></span>
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 星全价 *</label>
								<div class="col-sm-8">
									<input type="text" id="starPrice" placeholder="星全价" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 指导价 *</label>
								<div class="col-sm-8">
									<input type="text" id="guidancePrice" placeholder="指导价" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 优惠金额 *</label>
								<div class="col-sm-8">
									<input type="text" id="discount" placeholder="优惠金额" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 落地参考价 *</label>
								<div class="col-sm-8">
									<input type="text" id="actualPrice" placeholder="落地参考价" class="col-xs-10 col-sm-5">万
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车辆图片 *</label>
								<div class="col-sm-8">
									<input type="file" id="img" name="img" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点大图 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic1" name="pic1" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点小图1 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic2" name="pic2" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点小图2 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic3" name="pic3" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型配置亮点小图3 *</label>
								<div class="col-sm-8">
									<input type="file" id="pic4" name="pic4" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型参数 *</label>
								<div class="col-sm-8">
									<input type="file" id="excel1" name="excel1" value="">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-4 control-label"> 车型参数配置 *</label>
								<div class="col-sm-8">
									<input type="file" id="excel2" name="excel2" value="">
								</div>
							</div>
						</div>
					</form>
					<div class="modal-footer">
						<button id="editProductInfoButton" type="button" class="btn btn-sm btn-success">
							<i class="icon-ok"></i>保存
						</button>
						<button data-bb-handler="button" type="button" class="btn btn-sm closeEditProductInfo">取消
						</button>
					</div>
				</div>
			</div>
		</div>
		<div class="bg-warper" style="display: none;z-index: 9999;opacity: .7;width: 100%;height: 100%;position: fixed;top: 0;left: 0;background-color: #000;"></div>
		<!-- basic scripts -->
		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='/public/static/admin/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='/public/static/admin/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->

		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='/public/static/admin/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="/public/static/admin/js/bootstrap.min.js"></script>
		<script src="/public/static/admin/js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->

		<!-- ace scripts -->

		<script src="/public/static/admin/js/ace-elements.min.js"></script>
		<script src="/public/static/admin/js/ace.min.js"></script>
		<script src="/public/static/admin/js/jquery.form.js"></script>
</body>
</html>
<script type="text/javascript">
$("#logOut").click(function(){
    $.ajax({
        type: "POST",
        url: "/admin/index/logOut",
        dataType: "json",
        success: function(data){
            if (data['code'] == 0) {
                alert(data['msg']);
            } else {
                window.location = data['url'];
            }
        }
    });
});

$("#addProduct").click(function(){
	$("#addProductInfo").css("display","block");
});

$(".closeAddProductInfo").click(function() {
	$("#addProductInfo").css("display","none");
});

$("#addProductInfoButton").click(function(){

	var productBrandId = $("#addProductInfo :input[name='productBrandSelect']").find("option:selected").val();
	if (productBrandId == null || productBrandId == undefined || productBrandId == "") {
		alert("请选择品牌！");
		return;
	}
	/*
	var productBrandName = $("#addProductInfo :input[name='productBrandSelect']").find("option:selected").attr('data-value');
	*/
	var name = $("#addProductInfo #name").val();
	if (name == null || name == undefined || name == "") {
		alert("请填写名称！");
		return;
	}

	var abstract = $("#addProductInfo #abstract").val();
	if (abstract == null || abstract == undefined || abstract == "") {
		alert("请填写简介！");
		return;
	}

	var isHot = $("#addProductInfo input[name='isHot']:checked").val();
	if (isHot != null && isHot != undefined && isHot == "Yes") {
		isHot = 1;
	} else {
		isHot = 0;
	}

	var starPrice = $("#addProductInfo #starPrice").val();
	if (starPrice == null || starPrice == undefined || starPrice == "") {
		alert("请填写星全价！");
		return;
	}
	if(isNaN(starPrice)) {
		alert("星全价请填写数字！");
		return;
	}

	var guidancePrice = $("#addProductInfo #guidancePrice").val();
	if (guidancePrice == null || guidancePrice == undefined || guidancePrice == "") {
		alert("请填写指导价！");
		return;
	}
	if(isNaN(guidancePrice)) {
		alert("指导价请填写数字！");
		return;
	}

	var discount = $("#addProductInfo #discount").val();
	if (discount == null || discount == undefined || discount == "") {
		alert("请填写优惠金额 ！");
		return;
	}
	if(isNaN(discount)) {
		alert("优惠金额请填写数字！");
		return;
	}
	
	var actualPrice = $("#addProductInfo #actualPrice").val();
	if (actualPrice == null || actualPrice == undefined || actualPrice == "") {
		alert("请填写落地参考价 ！");
		return;
	}
	if(isNaN(actualPrice)) {
		alert("落地参考价请填写数字！");
		return;
	}
	
	var img = $("#addProductInfo #img").val();
	if (img == null || img == undefined || img == "") {
		alert("品牌图片不允许为空！");
		return;
	}

	var pic1 = $("#addProductInfo #pic1").val();
	if (pic1 == null || pic1 == undefined || pic1 == "") {
		alert("车型配置亮点大图不允许为空！");
		return;
	}

	var pic2 = $("#addProductInfo #pic2").val();
	if (pic2 == null || pic2 == undefined || pic2 == "") {
		alert("车型配置亮点小图1不允许为空！");
		return;
	}

	var pic3 = $("#addProductInfo #pic3").val();
	if (pic3 == null || pic3 == undefined || pic3 == "") {
		alert("车型配置亮点小图2不允许为空！");
		return;
	}
	
	var pic4 = $("#addProductInfo #pic4").val();
	if (pic4 == null || pic4 == undefined || pic4 == "") {
		alert("车型配置亮点小图3不允许为空！");
		return;
	}
	
	var excel1 = $("#addProductInfo #excel1").val();
	if (excel1 == null || excel1 == undefined || excel1 == "") {
		alert("车型参数不允许为空！");
		return;
	}

	var excel2 = $("#addProductInfo #excel2").val();
	if (excel2 == null || excel2 == undefined || excel2 == "") {
		alert("车型参数配置不允许为空！");
		return;
	}
	$(".bg-warper").css("display","block");
	var data = {
        	"brandId":productBrandId,
        	"name":name,
        	"abstract":abstract,
        	"isHot":isHot,
        	"starPrice":starPrice,
        	"guidancePrice":guidancePrice,
        	"discount":discount,
        	"actualPrice":actualPrice,
        	"img":img,
        	"pic1":pic1,
        	"pic2":pic2,
        	"pic3":pic3,
        	"pic4":pic4,
        	"excel1":excel1,
        	"excel2":excel2
        };
	var params = {
        url: "/admin/index/setProduct",
        type:"POST",
        dataType:"json",
        data:data,
        clearFomr: true,
        resetFomr: true,
        timeout: 3000,
        success:function(responseText,statusText,xhr,$form){
        	$(".bg-warper").css("display","none");
            if (responseText['code'] == 0) {
                alert(responseText['msg']);
            } else {
                location.reload();
            }
        },
        beforeSubmit: function(formData, jqForm, options){
        	for (var i = 0; i<formData.length;i++ ) {
        		if (formData[i]['name'] == 'img') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic1') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic2') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic3') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic4') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'excel1') {
        			if (formData[i]['value']['name'].indexOf("xlsx")==-1 &&
        				formData[i]['value']['name'].indexOf("xls")==-1) {
        				alert("excel类型有误,请上传xls|xlsx!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'excel2') {
        			if (formData[i]['value']['name'].indexOf("xlsx")==-1 &&
        				formData[i]['value']['name'].indexOf("xls")==-1) {
        				alert("excel类型有误,请上传xls|xlsx!");  
						return false;
        			}
        		}
        	}

        }
    };
	$("#productForm").ajaxSubmit(params);
	return false;
});

function editProduct(id) {
	$(".bg-warper").css("display","block");
	$.ajax({
        type: "POST",
        url: "/admin/index/getProdcut",
        data:{
        	"id":id
        },
        dataType: "json",
        success: function(resp){
        	$(".bg-warper").css("display","none");
            if (resp['code'] == 0) {
                alert(resp['msg']);
                return;
            } else {
            	resp['data'] = resp['data'][0];
                var id = resp['data']['id'];
                var brandId = resp['data']['brand_id'];
                var name = resp['data']['name'];
                var abstract = resp['data']['abstract'];
                var actualPrice = resp['data']['actual_price'];
                var discount = resp['data']['discount'];
                var guidancePrice = resp['data']['guidance_price'];
                var isHot = resp['data']['is_hot'];
                var starPrice = resp['data']['star_price'];
				
                $("#editProductInfo").css("display","block");

                $("#editProductInfo .isHotCheckbox").html('<input type="checkbox" value="Yes" offval="No" id="isHot" name="isHot" role="checkbox" class="editable ace ace-switch ace-switch-5"><span class="lbl"></span>');
                $("#editProductInfo #productId").val(id);
                $("#editProductInfo #name").val(name);
                $("#editProductInfo #abstract").val(abstract);
                if (isHot != 1) {
					$("#editProductInfo [name='isHot']").removeAttr("checked");
                } else {
                	$("#editProductInfo [name='isHot']").attr("checked",'true');
                }
				$("#editProductInfo #actualPrice").val(actualPrice);
				$("#editProductInfo #discount").val(discount);
                $("#editProductInfo #guidancePrice").val(guidancePrice);
                $("#editProductInfo #starPrice").val(starPrice);
                var brandListJson = '<?php echo $jsonBlist;?>';
                brandListJson = eval('(' + brandListJson + ')');
                var html = '<option value="-1">请选择品牌</option>';
                for (var i=0;i<brandListJson.length;i++) {
                	if (brandListJson[i]['id'] == brandId) {
						html += "<option value='"+brandListJson[i]['id']+"' selected='selected'>"+brandListJson[i]['name']+"</option>";
                	} else {
                		html += "<option value='"+brandListJson[i]['id']+"'>"+brandListJson[i]['name']+"</option>";
                	}
                }
                $("#editProductInfo [name='productBrandSelect']").html(html);
            }
        }
    });
}

$(".closeEditProductInfo").click(function() {
	$("#editProductInfo").css("display","none");
});

function delProduct(id) {
	$.ajax({
        type: "POST",
        url: "/admin/index/delProduct",
        data:{
        	"id":id
        },
        dataType: "json",
        success: function(resp){
            if (resp['code'] == 0) {
                alert(resp['msg']);
                return;
            } else {
            	location.reload();
            }
        }
    })
}
$("#editProductInfoButton").click(function() {
	$(".bg-warper").css("display","block");
	var id = $("#editProductInfo #productId").val();

	var productBrandId = $("#editProductInfo :input[name='productBrandSelect']").find("option:selected").val();
	if (productBrandId == null || productBrandId == undefined || productBrandId == "") {
		alert("请选择品牌！");
		return;
	}
	/*
	var productBrandName = $("#addProductInfo :input[name='productBrandSelect']").find("option:selected").attr('data-value');
	*/
	var name = $("#editProductInfo #name").val();
	if (name == null || name == undefined || name == "") {
		alert("请填写名称！");
		return;
	}

	var abstract = $("#editProductInfo #abstract").val();
	if (abstract == null || abstract == undefined || abstract == "") {
		alert("请填写简介！");
		return;
	}

	var isHot = $("#editProductInfo input[name='isHot']:checked").val();
	if (isHot != null && isHot != undefined && isHot == "Yes") {
		isHot = 1;
	} else {
		isHot = 0;
	}

	var starPrice = $("#editProductInfo #starPrice").val();
	if (starPrice == null || starPrice == undefined || starPrice == "") {
		alert("请填写星全价！");
		return;
	}
	if(isNaN(starPrice)) {
		alert("星全价请填写数字！");
		return;
	}

	var guidancePrice = $("#editProductInfo #guidancePrice").val();
	if (guidancePrice == null || guidancePrice == undefined || guidancePrice == "") {
		alert("请填写指导价！");
		return;
	}
	if(isNaN(guidancePrice)) {
		alert("指导价请填写数字！");
		return;
	}

	var discount = $("#editProductInfo #discount").val();
	if (discount == null || discount == undefined || discount == "") {
		alert("请填写优惠金额 ！");
		return;
	}
	if(isNaN(discount)) {
		alert("优惠金额请填写数字！");
		return;
	}
	
	var actualPrice = $("#editProductInfo #actualPrice").val();
	if (actualPrice == null || actualPrice == undefined || actualPrice == "") {
		alert("请填写落地参考价 ！");
		return;
	}
	if(isNaN(actualPrice)) {
		alert("落地参考价请填写数字！");
		return;
	}
	
	var img = $("#editProductInfo #img").val();
	if (img == null || img == undefined || img == "") {
		alert("品牌图片不允许为空！");
		return;
	}

	var pic1 = $("#editProductInfo #pic1").val();
	if (pic1 == null || pic1 == undefined || pic1 == "") {
		alert("车型配置亮点大图不允许为空！");
		return;
	}

	var pic2 = $("#editProductInfo #pic2").val();
	if (pic2 == null || pic2 == undefined || pic2 == "") {
		alert("车型配置亮点小图1不允许为空！");
		return;
	}

	var pic3 = $("#editProductInfo #pic3").val();
	if (pic3 == null || pic3 == undefined || pic3 == "") {
		alert("车型配置亮点小图2不允许为空！");
		return;
	}
	
	var pic4 = $("#editProductInfo #pic4").val();
	if (pic4 == null || pic4 == undefined || pic4 == "") {
		alert("车型配置亮点小图3不允许为空！");
		return;
	}
	
	var excel1 = $("#editProductInfo #excel1").val();
	if (excel1 == null || excel1 == undefined || excel1 == "") {
		alert("车型参数不允许为空！");
		return;
	}


	var excel2 = $("#editProductInfo #excel2").val();
	if (excel2 == null || excel2 == undefined || excel2 == "") {
		alert("车型参数配置不允许为空！");
		return;
	}
	var data = {
			"id":id,
        	"brandId":productBrandId,
        	"name":name,
        	"abstract":abstract,
        	"isHot":isHot,
        	"starPrice":starPrice,
        	"guidancePrice":guidancePrice,
        	"discount":discount,
        	"actualPrice":actualPrice,
        	"img":img,
        	"pic1":pic1,
        	"pic2":pic2,
        	"pic3":pic3,
        	"pic4":pic4,
        	"excel1":excel1,
        	"excel2":excel2
        };
	var params = {
        url: "/admin/index/setProduct",
        type:"POST",
        dataType:"json",
        data:data,
        clearFomr: true,
        resetFomr: true,
        timeout: 3000,
        success:function(responseText,statusText,xhr,$form){
        	$(".bg-warper").css("display","none");
            if (responseText['code'] == 0) {
                alert(responseText['msg']);
            } else {
                location.reload();
            }
        },
        beforeSubmit: function(formData, jqForm, options){
        	for (var i = 0; i<formData.length;i++ ) {
        		if (formData[i]['name'] == 'img') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic1') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic2') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic3') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'pic4') {
        			if (formData[i]['value']['type'].indexOf("image/")==-1) {
        				alert("图片类型有误,请上传图片!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'excel1') {
        			if (formData[i]['value']['name'].indexOf("xlsx")==-1 &&
        				formData[i]['value']['name'].indexOf("xls")==-1) {
        				alert("excel类型有误,请上传xls|xlsx!");  
						return false;
        			}
        		}
        		if (formData[i]['name'] == 'excel2') {
        			if (formData[i]['value']['name'].indexOf("xlsx")==-1 &&
        				formData[i]['value']['name'].indexOf("xls")==-1) {
        				alert("excel类型有误,请上传xls|xlsx!");  
						return false;
        			}
        		}
        	}

        }
    };
	$("#editProductForm").ajaxSubmit(params);
	return false;
});


</script>
